<%--
  @author Duminda Dharmakeerthi
  @author Supun Nimesh Karunathilaka
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dateSelector.js"></script>
<script src="${pageContext.request.contextPath}/js/landRegistration/vestingOrder.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        validateVestingOrderDetails();

    });

    function validateVestingOrderDetails() {
        $('#issueDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });
        $('#folioDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });
    }


    function initialValidate() {
        initialVestingOrder();
    }
    function detailValidate() {
//        alert("detail");
    }
    function showViolationComment() {
        $('#violationComment').show();
    }

    function hideViolationComment() {
        $('#violationComment').hide();
        $('#conditionsViolationComment').val('');
    }

    function violationCommentClick() {
        if ($('#conditionsViolatedOrNot0').is(':checked')) {
            hideViolationComment();
        } else {
            showViolationComment();
        }
    }
</script>
<script type="text/javascript" language="javascript">
    function showAcquiredStatus() {
        $('#acquired').show();
    }

    function hideAcquiredStatus() {
        $('#acquired').hide();
    }
    function showEncroachment() {
        $('#encroachmentDescriptionRow').show();
    }

    function hideEncroachment() {
        $('#encroachmentDescriptionRow').hide();
    }

    function disableFields() {
        var fields = new Array(
                'referenceNo',
                'issueDate',
                'folioNo',
                'folioDate',
                'folioLocation',
                'acquiredStatusNo',
                'acquiredStatusYes',
                'acquiredDescription',
                'encroachmentYes',
                'encroachmentNo',
                'encroachmentDescription',
                'developmentState',
                'conditionsViolatedOrNot0',
                'conditionsViolatedOrNot1',
                'clientType2',
                'clientType3',
                'clieantLocalAuthorityId',
                'conditionsViolationComment',
                'name',
                'address'
                );
        enableFields(fields);
    }

    $(function () {
        if ($('#acquiredDescription').val().length > 0) {
            $('#acquiredStatusYes').attr('checked', true);
            $('#acquired').show();
        } else {
            $('#acquiredStatusNo').attr('checked', true);
            $('#acquired').hide();
        }
        var approvalState = $('#approvalState').val();
        if (approvalState == 'PENDING' && (  (  ($('#userRole').val() == 'ORDS') ) || (  ($('#editMode').val() != 1)  &&   ($('#userRole').val() == 'ORIP')   ) ) ) {
            disableFields();
        }
        if ($('#landMode').val() == 'DETAIL') {
            violationCommentClick();
        } else {
            hideViolationComment();
        }
    });

    $(function() {
        var localAuthorityHtml = $('#localAuthority').html();
        var armedForceHtml = $('#armedForces').html();
        if ($('#landMode').val() == '') {
            $('#clientType2').attr('checked', true);
        }
        $('#clientType3').bind('click', function() {
            $('#armedForces').html(' ');
            $('#localAuthority').html(localAuthorityHtml);
            setClientName();
        });
        $('#clientType2').bind('click', function() {
            $('#localAuthority').html(' ');
            $('#armedForces').html(armedForceHtml);
        });
        if ($('#clientType3').is(':checked')) {
            $('#armedForces').html(' ');
            $('#localAuthority').html(localAuthorityHtml);
            setClientName();
        } else if ($('#clientType2').is(':checked')) {
            $('#localAuthority').html(' ');
            $('#armedForces').html(armedForceHtml);
        }

        if ($('#landMode').val() == 'DETAIL') {
            enableFields(new Array('clientType3', 'clientType2'));
        }
    });

    function setClientName() {
        $('#clientName').val($('#clieantLocalAuthorityId option:selected').text());
    }
</script>
<div id="tabs">
    <ul>
        <li><s:a href="#vesting-order-details"><s:label
                value="%{getText('vesting_order_details.label')}"/></s:a></li>
        <li><s:a href="#institute-details"><s:label value="%{getText('institute_details.label')}"/></s:a></li>
        <li><s:a href="#occupier-details"><s:label value="%{getText('occupier_details.label')}"/></s:a></li>
    </ul>
    <div id="vesting-order-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('vesting_order_no.label')}"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="referenceNo" name="alienation.referenceNo"/></td>
                <td><s:label value="%{getText('issue_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                               cssClass="date-format"/></td>
                <td><s:textfield id="issueDate" name="alienation.issueDate" onclick="selectDate('issueDate')"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_no.label')}"/></td>
                <td><s:textfield id="folioNo" name="alienation.folioNumber"/></td>
                <td><s:label value="%{getText('folio_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                               cssClass="date-format"/></td>
                <td><s:textfield id="folioDate" name="alienation.folioDate" onclick="selectDate('folioDate')"
                                 onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_location.label')}"/></td>
                <td colspan="3"><s:textarea id="folioLocation" name="alienation.folioLocation" rows="1"
                                            cssClass="width-595-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('status.label')}"/></td>
                <td><s:label value="%{getText('state.label')}"/><input id="acquiredStatusNo" type="radio"
                                                                       name="acquired" value="0"
                                                                       onclick="hideAcquiredStatus()"/></td>
                <td colspan="2"><s:label value="%{getText('acquired.label')}"/><input type="radio"
                                                                                      id="acquiredStatusYes"
                                                                                      name="acquired"
                                                                                      value="1"
                                                                                      onclick="showAcquiredStatus()"/>
                </td>
            </tr>
            <tr id="acquired">
                <td><s:label value="%{getText('if_acquired_purpose.label')}"/></td>
                <td colspan="3"><s:textarea id="acquiredDescription"
                                            name="alienation.acquiredDescription"
                                            cssClass="width-595-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('encroachment.label')}"/></td>
                <td><s:label value="%{getText('yes.label')}"/><input type="radio" id="encroachmentYes"
                                                                     name="encroachment"
                                                                     checked="checked" value="1"
                                                                     onclick="showEncroachment()"/></td>
                <td colspan="2"><s:label value="%{getText('no.label')}"/><input type="radio" id="encroachmentNo"
                                                                                name="encroachment"
                                                                                value="0"
                                                                                onclick="hideEncroachment()"/>
                </td>
            </tr>
            <tr id="encroachmentDescriptionRow">
                <td><s:label value="%{getText('encroachment_description.label')}"/></td>
                <td colspan="3">
                    <s:textarea id="encroachmentDescription" name="alienation.encroachmentDescription"
                                cssClass="width-595-px"/>
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('developed_status.label')}"/></td>
                <td colspan="3" class="left-align">
                    <s:textarea id="developmentState" name="alienation.developmentState"
                                cssClass="width-595-px"/>
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('conditionsViolatedOrNot.label')}"/></td>
                <td colspan="2"><s:radio id="conditionsViolatedOrNot" name="alienation.conditionsViolatedOrNot"
                                         list="#@java.util.HashMap@{'1':getText('yes.label'),'0':getText('no.label')}"
                                         onclick="violationCommentClick()"/></td>
            </tr>
            <tr id="violationComment">
                <td><s:label value="%{getText('conditionsViolationComment.label')}"/></td>
                <td colspan="3"><s:textarea id="conditionsViolationComment" name="alienation.conditionsViolationComment"
                                            rows="1"
                                            cssClass="width-595-px"/></td>
            </tr>
        </table>
    </div>
    <div id="institute-details">
        <table class="width-100">
            <tr>
                <td align="center" colspan="4">
                    <s:radio id="clientType" name="alienation.holder.holderType"
                             list="#@java.util.HashMap@{'2':getText('armed_forces.label'),'3':getText('local_authority.label')}"/>
                    <s:if test="land.mode.ordinal() == 1">
                        <s:hidden name="alienation.holder.holderType"/>
                    </s:if>
                </td>
            </tr>
        </table>
        <table id="armedForces" class="width-100">
            <tr>
                <td><s:label value="%{getText('name_of_client.label')}"/></td>
                <td colspan="3">
                    <s:textarea id="name" name="alienation.holder.name" cssClass="width-595-px"/>
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('address_of_client.label')}"/></td>
                <td colspan="3"><s:textarea id="address" name="alienation.holder.contacts.address"
                                            cssClass="width-595-px"/></td>
            </tr>
        </table>
        <table id="localAuthority" class="width-100">
            <tr>
                <td><s:label value="%{getText('local_authority.label')}"/></td>
                <td colspan="3">
                    <s:select id="clieantLocalAuthorityId" name="alienation.holder.localAuthority.id"
                              list="localAuthorityList" onchange="setClientName()" cssClass="width-200-px"/>
                    <s:hidden id="clientName" name="alienation.holder.name"/>
                </td>
            </tr>
        </table>
    </div>
    <div id="occupier-details">
        <table class="width-100">
            <s:include value="../encroacherDetails.jsp"/>
        </table>
    </div>
</div>

<s:hidden name="alienation.id"/>
<s:hidden name="alienation.holder.id"/>
<s:hidden name="alienation.holder.contacts.id"/>

<s:hidden id="pls_enter_reference_no" value="%{getText('pls_enter_reference_no')}"/>
<s:hidden id="pls_enter_name_of_the_land" value="%{getText('pls_enter_name_of_the_land')}"/>
<s:hidden id="pls_enter_plan_no" value="%{getText('pls_enter_plan_no')}"/>
<s:hidden id="pls_enter_lot_no" value="%{getText('pls_enter_lot_no')}"/>
<s:hidden id="pls_enter_valid_no" value="%{getText('pls_enter_valid_no')}"/>
<s:hidden id="pls_select_gn_division" value="%{getText('pls_select_gn_division')}"/>